#!/usr/bin/env python
# -*- coding:utf-8 -*-

import xml.dom.minidom
from google.appengine.ext import db
from google.appengine.ext import ndb
from parse import getId

class QImage(ndb.Model):
    data = ndb.BlobProperty()

class Khokng(db.Model):
    choanmiann = db.StringProperty() # full name
    nihun = db.StringProperty() # year
    hothau = db.StringProperty() # code
    tengte = db.IntegerProperty() # class
    khochhi = db.StringProperty() # examset
    choopiat = db.StringProperty() # category
    khobok = db.StringProperty() # subject
class Tebok(db.Model):
    choanmiann = db.StringProperty() # full name
    nihun = db.StringProperty() # year
    hothau = db.StringProperty() # code
    tengte = db.IntegerProperty() # class
    khochhi = db.StringProperty() # examset
    choopiat = db.StringProperty() # category
    khobok = db.StringProperty() # subject
    thauhang = db.TextProperty()#required=True) # content
    tootoo = db.BlobProperty() # figure
    toeho = db.StringProperty() # index
    tiamsoo = db.IntegerProperty() # points
    khamho = db.StringProperty() # unique ID of question
    khokng = db.ReferenceProperty(Khokng)

def getXMLData(Id):
  qxml = QXML.get_by_id(Id)
  if (qxml):
    return qxml.data
  else:
    return None

def getImageData(Id):
  image = QImage.get_by_id(Id)
  if (image):
    return image.data
  else:
    return None

def getAllXMLList():
  xmls = QXML.query()
  HTMLStr = u'<div style="margin: 1em;">'
  for xml in xmls:
    qId = xml.key.id()
    HTMLStr += u'<a href="/show?id=%s">%s</a><br />' % (qId, qId)
  HTMLStr += u'</div>'
  return HTMLStr

def chhoeTebok(str):
  return